/**
 * @author 蓝面小生
 * base simpleui www.simpleui.org
 */
$.extend($, {
        loadTip: function(text, container){
            return new Tip(text, container, "load");
        },
        successTip: function(text, container){
            return new Tip(text, container, "success");
        },
        infoTip: function(text, container){
            return new Tip(text, container, "info");
        },
        alertTip: function(text, container){
            return new Tip(text, container, "alert");
        }
    });
    Tip = function(text, container, type){
        this.template = '<div class="simple-load"><span class="simple-load-l"></span><div class="simple-load-bg"></div><div class="simple-load-text"><i></i><label>正在导入中...</label></div></div>';
        this.text = text;
        this.node = $(this.template).clone();
        this.container = typeof container == "string" ? $(container) : container;
        this.type = type;
        this.init();
    }
    Tip.prototype = {
        init: function(){
            $(".simple-load").remove();
            var self = this;
            switch (this.type) {
                case "load":
					this.node.addClass("simple-tip-load");
                    break;
                case "success":
                    this.node.addClass("simple-tip-success");
                    break;
                case "info":
                    this.node.addClass("simple-tip-info");
                    break;
                case "alert":
                    this.node.addClass("simple-tip-alert");
                    break;
            }
            this.show();
           if (this.type != "load") {
               setTimeout(function(){
                    self.hide();
                }, 2000);
            }
        },
        show: function(){
            var self = this;
            $(document.body).append(this.node);
            this.node.find(".simple-load-text label").html(this.text);
			//fix ie6
			var simpleTextWidth=this.node.find(".simple-load-text").width()+parseInt(this.node.find(".simple-load-text").css("paddingLeft"));
			this.node.width(simpleTextWidth);
			this.node.find(".simple-load-bg").width(simpleTextWidth+10);
            this.setPosition();
            //listen resize
            $(window).resize(function(){
                self.setPosition();
            });
        },
        hide: function(){
            this.node.remove();
        },
        setPosition: function(){
            this.container = this.container || $(document);
            var width = this.container.width(), height = this.container.height(), nodeWidth = this.node.width(), nodeHeight = this.node.height();
            this.node.css({
                top: (height - nodeHeight) / 3,
                left: ((width - nodeWidth) / 2) + 12
            });
        }
    }